package data;

import java.io.IOException;
import java.util.List;

import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Gesture;

public class LeapMotionInterface implements Runnable {
	private LeapMotionListener leapListener;
	private Controller controller;
	public boolean running = false;

	public LeapMotionInterface(List<Gesture.Type> gestureTypes) {
		leapListener = new LeapMotionListener(gestureTypes);
		controller = new Controller();
		controller.addListener(leapListener);
	}

	@Override
	public void run() {
		while (running) {
			try {
				System.in.read();
			} catch (IOException exception) {
				exception.printStackTrace();
			}
			controller.removeListener(leapListener);
		}
	}
	
	/**
	 * Enable/disable the thread's execution.
	 * As there is no low level access to the Leap Motion API,
	 * disabling probably will not work.
	 */
	public void toggle() {
		if (this.running == false) {
			this.running = true;
		} else {
			this.running = false;
		}
	}
	
	public void removeListener() {
		controller.removeListener(leapListener);
	}
	
	public List<Gesture> mostRecentGestures() {
		return leapListener.mostRecentGestures();
	}
	
	public boolean hasBufferChanged() {
		return leapListener.hasBufferChanged();
	}

}
